package com.example.springboot.exception;

/*
 * 功能：自定义异常
 * 日期：2024-3-24 15:21
 * 作者：RabbitQ
 */

import com.example.springboot.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalException {

    //
    @ExceptionHandler(ServiceException.class)
    @ResponseBody //将Result对象转为jason格式
    public Result serviceException(ServiceException ex){
        return Result.error(ex.getCode(), ex.getMessage());
    }

}
